/*
Copyright 2010 Johan Maasing

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package nu.zoom.android.gdata.project.integration;

import java.io.IOException;
import java.util.List;

import android.net.Uri;

import com.google.api.client.util.Key;

public interface ProjectHostingClient {
	public static final String HOSTING_HOME = "https://code.google.com";
	public static final String FEED_PREFIX = HOSTING_HOME + "/feeds/issues/p/";
	public static final String FEED_SUFFIX = "/issues/full";
	public static final String WEB_ISSUELIST_PREFIX = HOSTING_HOME + "/p/";
	public static final String WEB_ISSUELIST_SUFFIX = "/issues/list";

	public IssueOverviewFeed getIssues(Uri uri, int startPosition,
			int batchSize, String cannedQuery) throws IOException;

	public IssueDetail getIssue(Uri uri) throws IOException;

	public CommentFeed getComments(Uri uri, int startPosition, int batchSize)
			throws IOException;

	public abstract static class Feed<T> {
		@Key("openSearch:totalResults")
		public int totalResult;
		@Key("entry")
		public List<T> entries;
	}

	public static class IssueOverviewFeed extends Feed<IssueOverview> {
	}

	public static class IssueOverview {
		@Key("title")
		public String title;
		@Key("id")
		public String id;

		@Override
		/**
		 * Returns the issue title. Used in list views.
		 */
		public String toString() {
			return title;
		}

	}

	public static class IssueDetail {
		@Key("title")
		public String title;
		@Key("id")
		public String idUri;
		@Key("content")
		public String content;
		@Key("issues:id")
		public String id;
		@Key("issues:stars")
		public int stars;
		@Key("issues:label")
		public List<String> labels;
		@Key("issues:state")
		public String state;
		@Key("issues:status")
		public String status;
		@Key("published")
		public String published;
		@Key("issues:owner")
		public Owner owner;
		@Key("author")
		public Author author;
		@Key("link")
		public List<Link> links;
	}

	public static class CommentFeed extends Feed<Comment> {
	}

	public static class Comment {
		@Key("title")
		public String title;
		@Key("content")
		public String content;
		@Key("published")
		public String published;
		@Key("link")
		public List<Link> links;
	}

	public static class Author {
		@Key("name")
		public String name;
		@Key("uri")
		public String uri;
	}

	public static class Owner {
		@Key("issues:username")
		public String username;
		@Key("issues:uri")
		public String uri;
	}

	public static class Link {
		@Key("@rel")
		public String rel;
		@Key("@type")
		public String type;
		@Key("@href")
		public String href;
	}
}
